package com.corpcredit.webapp.action;

import java.io.Serializable;

import com.corpcredit.model.Jbqk;
import com.corpcredit.model.Mqkfqk;
import com.corpcredit.webapp.action.BasePage;
import com.corpcredit.service.GenericManager;

public class MqkfqkForm extends BasePage implements Serializable {
    private GenericManager<Mqkfqk, Long> mqkfqkManager;
    private Mqkfqk mqkfqk = new Mqkfqk();
    private Long id;
    
    private Jbqk jbqk;

    public void setJbqk( Jbqk jbqk )
    {
        this.jbqk = jbqk;
    }
    
    public void setMqkfqkManager(GenericManager<Mqkfqk, Long> mqkfqkManager) {
        this.mqkfqkManager = mqkfqkManager;
    }

    public Mqkfqk getMqkfqk() {
        return mqkfqk;
    }

    public void setMqkfqk(Mqkfqk mqkfqk) {
        this.mqkfqk = mqkfqk;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String delete() {
        mqkfqkManager.remove(mqkfqk.getId());
        addMessage("mqkfqk.deleted");

        return "list";
    }

    public String edit() {
        // Comparison to zero (vs. null) is required with MyFaces 1.2.2, not with previous versions
        if (id != null && id != 0) {
            mqkfqk = mqkfqkManager.get(id);
        } else {
            mqkfqk = new Mqkfqk();
        }

        return "edit";
    }

    public String save() {
        boolean isNew = (mqkfqk.getId() == null || mqkfqk.getId() == 0);
        // set the related jbqk as a foreign key.
        mqkfqk.setJbqk( jbqk );
        mqkfqkManager.save(mqkfqk);

        String key = (isNew) ? "mqkfqk.added" : "mqkfqk.updated";
        addMessage(key);

        if (isNew) {
            return "list";
        } else {
            return "edit";
        }
    }
} 